<!DOCTYPE html>
<html>
<head>
    <title>门诊医生--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
	 $(function () {
		$('#newNav').click(function(){
				window.location.href="add.html";
		 });
    });
	
    	function checkall(){
			var alls=document.getElementsByName("check");
			var ch=document.getElementById("checkall");
			if(ch.checked){
				for(var i=0;i<alls.length;i++){
					alls[i].checked=true;	
				}	
			}else{
				for(var i=0;i<alls.length;i++){
					alls[i].checked=false;	
				}	
			}
		}
		function delAll(){
			var alls=document.getElementsByName("check");
			var ids=new Array();
			for(var i=0;i<alls.length;i++){
				if(alls[i].checked){
					ids.push(alls[i].value);
				}		
			}
			if(ids.length>0){
				if(confirm("确认操作?")){
					alert("成功!");
				}
			}else{
				alert("请选中要操作的项");
			}
		}
    </script>
</head>
<body>

<form id="myForm"  class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">医生编号：</td>
        <td><input type="text" name="doctorId" id="doctorId" value=""/></td>
		
        <td width="10%" class="tableleft">医生姓名：</td>
        <td><input type="text" name="doctorName" id="doctorName" value=""/></td>
		
        <td width="10%" class="tableleft">科室：</td>
        <td><input type="text" name="deptName" id="deptName" value=""/></td>
    </tr>
    <tr>
		  <td colspan="6"><center>
            <input  class="btn btn-primary" type="button" value="查询" >
            <button type="submit" class="btn btn-primary" type="button">清空</button> 
			</center>
        </td>
    </tr>
</table>
</form>
   
<table class="table table-bordered table-hover definewidth m10" >
   <thead>
    <tr>
    	<th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>医生编号</th>
        <th>医生姓名</th>
        <th>入院时间</th>
        <th>所属科室</th>
        <th>操作</th>
    </tr>
    </thead>
	   <tbody id="tbody"></tbody>
  </table>
  
  <table class="table table-bordered table-hover definewidth m10" >
  	<tr><th colspan="5">
        <div class="inline pull-right page">
            <a name="" id="firstPage" onclick="A()">第一页</a>
            <a name="" id="prePage" onclick="B()">上一页</a>
            <span id="currentPage"></span>
            <a name="" id="nextPage" onclick="C()">下一页</a>
            <a name="" id="lastPage" onclick="D()">最后一页</a>
            &nbsp;&nbsp;&nbsp;共<span id="total" class='current'></span>条记录
            <span id="pageNum"></span>/<span id="pages"></span>页
            <span id="pageSize" class="hidden"></span>
        </div>
		 <div><button type="button" class="btn btn-success" id="newNav">添加新医生</button>
             <button type="button" class="btn btn-success"  onclick="exportInfo()">导出Excel</button>
             导出文件位置:
             <input type="text" id="outStream" name="outStream">
		 </div>
		 </th></tr>
  </table>
  
</body>
<script>
    //页面加载完毕之后发送异步请求

    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }
    //加载数据
    loadData()
    function A() {
        if ($("#firstPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#firstPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };

    function B() {
        if ($("#prePage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#prePage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };

    function C() {
        if ($("#nextPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#nextPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };

    function D() {
        if ($("#lastPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#lastPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };

    function E(j) {
        $("#pageNum").html(j);
        loadData();
    };

    function fillPageData(pageInfo) {
        //填充信息
        $("#total").html(pageInfo.total);
        $("#pages").html(pageInfo.pages);
        $("#pageNum").html(pageInfo.pageNum);
        $("#pageSize").html(pageInfo.pageSize);
        let str = "";
        for (let i = 1; i <= pageInfo.pages; i++) {
            str += '<a onclick=E(' + i + ')>' + i + '</a>';
        }
        $("#currentPage").html(str);

        //设置按钮的属性值和样式
        $("#firstPage").attr("name", 1);
        $("#prePage").attr("name", pageInfo.prePage);
        $("#nextPage").attr("name", pageInfo.nextPage);
        $("#lastPage").attr("name", pageInfo.pages);
        $("#firstPage").removeClass("btn btn-small disabled");
        $("#prePage").removeClass("btn btn-small disabled");
        $("#nextPage").removeClass("btn btn-small disabled");
        $("#lastPage").removeClass("btn btn-small disabled");
        if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
            $("#firstPage").addClass("btn btn-small disabled");
            $("#prePage").addClass("btn btn-small disabled");
            $("#current1").addClass("btn btn-small disabled");
        }
        if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
            $("#nextPage").addClass("btn btn-small disabled");
            $("#lastPage").addClass("btn btn-small disabled");
        }
    }
    function loadData() {
        let pageNum = $("#pageNum").html();
        let pageSize = $("#pageSize").html();
        let id = $("#doctorId").val();
        let doctorName = $("#doctorName").val();
        let deptName = $("#deptName").val();
        $.ajax({
            url: "/Doctor/findDoctorAllPagination",
            type: 'GET',
            data: "id=" + id + "&doctorName=" + doctorName+"&deptName=" + deptName  +"&pageNum=" + pageNum + "&pageSize=" + pageSize,
            dataType: 'json',
            success: function (vo) {
                console.log(vo);
                let str = "";
                let data = vo.pageInfo.list;
                for (let i = 0; i < data.length; i++) {
                    let doctor_id = data[i].id;//病历号
                    let doctor_name = data[i].doctorName;//姓名
                    let doctor_inTime = data[i].inTime;//押金
                    let doctor_dept = data[i].dept==null?'无科室':data[i].dept.deptName;//余额
                    str += '<tr>' +
                        '        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>\n' +
                        '        <td style="vertical-align:middle;">' + doctor_id + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + doctor_name + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + doctor_inTime + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + doctor_dept + '</td>\n' +
                        '<td style="vertical-align:middle;"><a href="look.html?doctor_id='+data[i].id+'">详细信息</a>&nbsp;&nbsp;&nbsp;<a href="edit.html?doctor_id='+data[i].id+'" >更改</a></td>'+
                        '    </tr>'
                }
                $("#tbody").html(str);
                fillPageData(vo.pageInfo);
            }
        })
    }
    // 这样调用：
    function findDept(result) {
        $.ajax({
            type: "GET",
            url: "/dept/findDept",
            dataType: "json",
            success: function (vo) {
                let data = vo.list;

                let str = "";
                for (let i = 0; i < data.length; i++) {
                    if (result == data[i].deptId) {
                        str += "<option selected='selected'  value=\" " + data[i].deptId + "\" >" + data[i].deptName + "</option>\n"
                    } else {
                        str += "<option  value=\" " + data[i].deptId + "\" >" + data[i].deptName + "</option>\n"
                    }

                }
                $("#dept").html(str);

            },
        })

    }
//导出excel
    function exportInfo() {
        let doctorId = $("#doctorId").val();
        let doctorName = $("#doctorName").val();
        let deptName = $("#deptName").val();
        let outStream = $("#outStream").val();
        if (outStream == "") {
            alert("保存路径为空");
            return false;
        }
        $.ajax({
            type: "POST",
            data: "outStream="+outStream+"&doctorId=" + doctorId + "&doctorName=" + doctorName + "&deptName=" + deptName,
            dataType:"json",
            url: "/Doctor/excelInfo",
            success: function (vo) {
                alert(vo.msg)
                if(vo.code==200){
                    black();
                }
            }
        })
    }
</script>
</html>
